export declare const api_context_path = "/api/";

type IdType = string | number | string[] | number[];

type PageType = string | number;

type SizeType = string | number;

type SelectType = string | string[];

type KeyDataType = { [key: string]: any }

type WhereType = KeyDataType;

type FmtType = KeyDataType;

type JoinType = { [key: string]: MetaApiJoin };

type OrderType = string | string[]

interface MetaApiJoin {

    select?: SelectType;

    where?: WhereType;

    on?: { [key: string]: string };

    when?: KeyDataType;

    order?: OrderType;

    page?: PageType;

    size?: SizeType;
}

interface MetaApiBaseRequest {

    fmt?: FmtType;
}

export interface MetaApiFindRequest extends MetaApiBaseRequest {

    select?: SelectType;

    where?: WhereType;

    join?: JoinType;

    order?: OrderType;

    page?: PageType;

    size?: SizeType;
}

export interface MetaApiGetRequest extends MetaApiBaseRequest {

    id: IdType;

    where?: WhereType;

    select?: SelectType;

    join?: JoinType;
}

export interface MetaApiUpdateRequest extends MetaApiBaseRequest {

    id: IdType;

    where?: WhereType;

    data: KeyDataType;
}

export interface MetaApiSaveRequest extends MetaApiBaseRequest {

    back?: string | string[];

    async?: boolean;

    data: KeyDataType | KeyDataType[];
}

export interface MetaApiDelRequest extends MetaApiBaseRequest {

    id: IdType;

    where?: WhereType;
}

export const get_path_ = (name: string) => api_context_path + name + "/get";
export const find_path_ = (name: string) => api_context_path + name + "/find";
export const edit_path_ = (name: string) => api_context_path + name + "/edit";
export const del_path_ = (name: string) => api_context_path + name + "/del";
export const save_path_ = (name: string) => api_context_path + name + "/save";

export const as_ = (name: string, alias: string) => `${ name } ${ alias }`

export const eq_ = (column: string) => column;
export const ne_ = (column: string) => `${ column } !`;
export const gt_ = (column: string) => `${ column } >`;
export const ge_ = (column: string) => `${ column } >=`;
export const lt_ = (column: string) => `${ column } <`;
export const le_ = (column: string) => `${ column } <=`;
export const in_ = (column: string) => `${ column } .`;
export const not_in_ = (column: string) => `${ column } !.`;
export const like_ = (column: string) => `${ column } *`;
export const not_like_ = (column: string) => `${ column } !*`;
export const left_like_ = (column: string) => `${ column } {`;
export const right_like_ = (column: string) => `${ column } }`;
export const not_left_like_ = (column: string) => `${ column } !{`;
export const not_right_like_ = (column: string) => `${ column } !}`;
export const between_ = (column: string) => `${ column } ~`;
export const not_between_ = (column: string) => `${ column } !~`;
export const is_ = (column: string) => `${ column } :`;
export const is_not_ = (column: string) => `${ column } !:`;
